package com.xkw.boot.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.xkw.boot.sys.entity.User;

@Mapper // 添加此注解，便可以被扫描到
public interface UserMapper {
	/**
	 * 返回所有用户列表
	 * 
	 * @return
	 */
	@Select("SELECT * FROM SYS_USER")
	public List<User> findAllUser();

	/*
	 * 这个一个接口，但不需要实现它，用于 函数与SQL语句 的映射
	 */

	@Insert("insert into sys_user(name,sex) values(#{name},#{sex})")
	public void insertT(User user);

	@Delete("delete from sys_user where id=#{id}")
	public void deleteById(int id);

	@Update("update sys_user set name=#{name},sex=#{sex} where id=#{id}")
	public void updateT(User user);

	@Select("select * from sys_user where id=#{id}")
	public User getUser(int id);

	@Select("select * from sys_user")
	public List<User> getAllUsers();
	
	/**
	 * @description 根据条件查询客户信息 (分页查询) 倒叙 
	 * - asc 按升序排列 (不用写，默认使用这个) 
	 * - desc 按降序排列 
	 */
	@Select({"<script>",
		"select * from user",
		"where 1=1",
		"<if test='tel!=null and tel!=\"\"'>","and tel = #{tel}","</if>",
		"<if test='customname!=null and customname != \"\"'>","and customname = #{customname}","</if>",
		"<if test='sendemail!=null and sendemail !=\"\"'>","and send_email = #{sendemail}","</if>",
		"<if test='keywords!=null and keywords != \"\"'>","and keywords like '%${keywords}%'","</if>",
		"order by id desc limit #{pages},#{limit}",
		"</script>"})
	public List<User> findCustomByForm(@Param("tel") String tel,@Param("customname") String customname,
	            @Param("sendemail") String sendemail,@Param("keywords") String keywords,
	            @Param("pages") Integer pages,@Param("limit") Integer limit);

}
